﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SC.UserCenter.Infra;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.BookStore.Goods
{
    /// <summary>
    /// 商品类型
    /// </summary>
    [ApiExplorerSettings(GroupName = "v2")]
    public class AddGoodsTypeServices : ApplicationService , IAddGoodsTypeServices
    {
        /// <summary>
        /// 商品类型仓储
        /// </summary>
         IRepository<GoodsTypeInfor> repository;
        /// <summary>
        /// 构造函数依赖注入
        /// </summary>
        /// <param name="repository">商品类型仓储</param>
        public AddGoodsTypeServices(IRepository<GoodsTypeInfor> repository)
        {
            this.repository = repository;
        }
        /// <summary>
        /// 商品类型展示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GoodsShow()
        {
            var list=(await repository.GetQueryableAsync()).ToList();

            return ApiResult.Ok(list);
        }

        /// <summary>
        /// 商品类型
        /// </summary>
        /// <param name="goodsTypeDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> InsertGoodsType(GoodsTypeDTO goodsTypeDTO)
        {
            var entity=ObjectMapper.Map<GoodsTypeDTO, GoodsTypeInfor>(goodsTypeDTO);
            await repository.InsertAsync(entity);
            return  ApiResult.Ok("添加成功");
        }
    }
}
